package algorithm.stack;

/**
 * @author bingo
 * @Description    括号匹配
 * @Date 2018/6/2
 */
public class Solution {


    Stack<Character> stack = new ArrayStack(10);

    public boolean isValid(String s) {
        char[]  s2 = s.toCharArray();
        for(int i=0;i<s2.length;i++){
            if(s2[i]=='{'||s2[i]=='['||s2[i]=='('){
                stack.push(s2[i]);
            }else{
                char  top = stack.pop();
                if(s2[i]=='('&&top!=')'){ return  false; }
                if(s2[i]=='['&&top!=']'){ return  false; }
                if(s2[i]=='{'&&top!='}'){ return  false; }
                }
        }
        return  stack.isEmpty();
    }

    public static void main(String[] args) {
        String s = "[]{}()";
        Solution solution = new Solution();
        System.out.println(solution.isValid(s));

        }


}
